﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using RadioStream;
using Microsoft.MediaCenter.UI;

namespace RadioStream.Code
{
    class CRefresher
    {
        public CRefresher()
        {
            m_hostApplication = null;
        }

        public CRefresher(Application hostApplication)
        {
            if (null != hostApplication)
            {
                m_hostApplication = hostApplication;
            }
        }
        private Application m_hostApplication;

        public void Run()
        {
                while (null != m_hostApplication)
                {
                    m_hostApplication.RefreshSongInfo();
                    CSongInfo SongInfo = m_hostApplication.GetSongInfo;
                    int RefreshTimeSec = 5;
                    if (null != SongInfo) // in case we already know about the Song
                    {
                        RefreshTimeSec = Math.Max((SongInfo.GetRemainingTime / 2),RefreshTimeSec);
                    }
                    System.Threading.Thread.Sleep(RefreshTimeSec*1000);
                }
        }
    
    }
}
